package cn.zhang.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@Slf4j
public class StreamOutputController {

    @Resource(name = "deepseek")
    private ChatModel deepseekChatModel;

    @Resource(name = "qwen")
    private ChatModel qwenChatModel;


    @GetMapping(value = "/streamOutput/qwen/stream")
    public Flux<String> qwenStream(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        return qwenChatModel.stream(msg);
    }

    @GetMapping(value = "/streamOutput/deepseek/stream")
    public Flux<String> deepSeekStream(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        return deepseekChatModel.stream(msg);
    }

    @Resource(name = "deepseekChatClient")
    private ChatClient deepseekChatClient;

    @Resource(name = "qwenChatClient")
    private ChatClient qwenChatClient;

    @GetMapping(value = "/streamOutput/qwenClient/stream")
    public Flux<String> qwenClientStream(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        return qwenChatClient.prompt(msg).stream().content();
    }

    @GetMapping(value = "/streamOutput/deepseekClient/stream")
    public Flux<String> deepSeekClientStream(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        return deepseekChatClient.prompt().user(msg).stream().content();
    }

}
